
// lib
import { configure } from "mobx";
// config
import { LOCAL_ACCOUNT, LOCAL_AUTH } from "project/config";
// script & methods & public
import storageUtils from "utils/storageUtils";
// state class
import AppState from "./app.state";
import UserState from "./user.state";
import DataState from "./data.state";
import DictState from "./dict.state";
// 其它

configure({
  enforceActions: "never", // 禁止了严格模式,加快开发速度
});

// 创建全局state
export const appState = new AppState();
export const userState = new UserState();
export const dataState = new DataState();
export const dictState = new DictState();

// init
export function initUserState() {
  const account = storageUtils.getStore<Account>(LOCAL_ACCOUNT, true);
  if (account) {
    userState.setAccount(account);
  }
  const auth = storageUtils.getStore<string>(LOCAL_AUTH, true);
  if (auth) {
    userState.token = auth;
  }
}
